﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using IDAL;
using DBUtility;

namespace SqlDbDAL
{
    //与病人的操作有关的实现方法放这
    public class IPatientImpl:IPatient
    {
        /// <summary>
        /// 根据注册网号获取患者信息
        /// </summary>
        /// <param name="patientID"></param>
        /// <returns></returns>
        public DataTable getPatientDataTable(int patientID)
        {
            string strSQL = "select * from TB_PATIENT_INFO where NPATIENTID=" + patientID.ToString();

            SqlDataBase sqlDataBase = new SqlDataBase();
            DataTable patentInfoDT = new DataTable();
            patentInfoDT = sqlDataBase.GetDataTable(strSQL);
            if (patentInfoDT != null)
                return patentInfoDT;
            else
                return null;
        }


        /// <summary>
        /// 更具病人注册网号获取患者的看病历史（留言历史），以倒序排序
        /// </summary>
        /// <param name="patientID"></param>
        /// <returns></returns>
        public DataTable getPatientRecordDT(int patientID)
        {
            string strSQL = "select * from TB_MEDICAL_RECORDS where NPATIENTID=" + patientID.ToString() + " order by DASKTIME desc";
            SqlDataBase sqldatabase = new SqlDataBase();
            DataTable patientRecordDT = new DataTable();
            patientRecordDT = sqldatabase.GetDataTable(strSQL);
            if (patientRecordDT != null)
                return patientRecordDT;
            else
                return null;
        }


        public int patientAsk(int patientID, string title, string strdate, string comment, int answernot)
        {
            string sqlSQL = "insert into TB_MEDICAL_RECORDS(NPATIENTID,STITLE,DASKTIME,SASK_PATI,NANSWER) values("+patientID.ToString()+",'"+title+"','"+strdate+"','"+comment+"',"+answernot.ToString()+")";
            SqlDataBase sqldatabase = new SqlDataBase();
            bool k = sqldatabase.ExeSQL(sqlSQL);
            if (k)
                return 1;
            else
                return 0;
        }
    }
}
